//
//  RemoteLoginApi.m
//  EMMApp
//
//  Created by Mac on 16/8/12.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "RemoteLoginApi.h"
#define myUrlMethod @"remoteLogin"
#define myUrlPath @"/appapi/remoteLogin"

@implementation RemoteLoginApi
{
    NSString *_body;
}
#pragma mark - 初始化

- (instancetype)initWith {
    self = [super init];
    if (self) {
        NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
        NSString *merchantId = [userdf objectForKey:@"merchantId"];
        NSString *userId = [userdf objectForKey:@"userNameId"];
        NSString *token = [userdf objectForKey:@"is_login"];
        
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        [params setValue:apiVersion forKey:@"version"];
        [params setValue:[IDTools devId2] forKey:@"terminalCode"];
        [params setValue:merchantId forKey:@"merchantId"];
        [params setValue:userId forKey:@"userId"];
        [params setValue:token forKey:@"token"];
        [params setValue:[IDTools idString2] forKey:@"deviceToken"];//极光注册码
        _body = [@{@"params" : params} JSONString];
        NSLog(@"---%@:\n %@%@?body=%@", myUrlMethod, apiBaseUrl, myUrlPath, _body);
        
    }
    return self;
}


#pragma mark - 父类继承拓展


//域名后面的网址信息 ————————————
- (NSString *)requestUrl
{
    return myUrlPath;
}

//需要传入的参数 ——————————————
- (id)requestArgument
{
    return @{ @"body" : _body };
}

/*返回数据请求的方式————————————————此处还应填此参数 数据请求方式，父类有，所以不用写
 - (YTKRequestMethod)requestMethod
 {
 return YTKRequestMethodPost;
 }
 */

//______________________


- (NSString *)methodString
{
    return myUrlMethod;
}


#pragma mark - 通用

//将获取的数据直接填充到model里面 获得model
- (RemoteLogin *)resultData
{
    id myObj = [IDTools jsonStrToObjc:self.responseString method:myUrlMethod];
    
    RemoteLogin *data = (RemoteLogin *)myObj;
    
    NSLog(@"%@ resultData is %@", myUrlMethod, data);
    
    return data;
}

- (BOOL)isSuccess
{
    // 得到model里面返回码 1代表成功
    NSString *str = [[self resultData] result];
    if ([NSString isStringEmpty:str] || ![str isEqualToString:@"1"]) {
        return NO;
    } else {
        return YES;
    }
}

@end
